package com.example.game.entity;

import java.awt.*;

public class Enemy {
    private int x;
    private int y;
    private int width = 40;
    private int height = 40;
    private int speed = 2;
    private boolean movingRight = true;
    private int patrolDistance = 200;
    private int startX;
    
    public Enemy(int x, int y) {
        this.x = x;
        this.y = y;
        this.startX = x;
    }
    
    public void update() {
        if (movingRight) {
            x += speed;
            if (x >= startX + patrolDistance) {
                movingRight = false;
            }
        } else {
            x -= speed;
            if (x <= startX) {
                movingRight = true;
            }
        }
    }
    
    public void draw(Graphics g) {
        g.setColor(Color.RED);
        g.fillRect(x, y, width, height);
    }
    
    public Rectangle getBounds() {
        return new Rectangle(x, y, width, height);
    }
    
    public boolean isHit(Rectangle bullet) {
        return getBounds().intersects(bullet);
    }
}
